<?php

class IdcardController extends BaseController {

//ID Card Type
	public function getIdcardtype()
	{
		Session::forget('filter');
		$idcardtype = DB::table('ref_idcard_type')
				->where('idcard_type_isdelete','=',0)
				->paginate(10);
		return View::make('admin.idcard.idcardtype')->with('idcardtype',$idcardtype);
	}

	public function postIdcardtype()
	{
		$filter = Input::get('filter');
		Session::put('filter',Input::get('filter'));
		$idcardtype = DB::table('ref_idcard_type')
		->where('idcard_type_isdelete','=',0)
		->where('idcard_type_name','LIKE','%'.$filter.'%')
		->paginate(10);
		return View::make('admin.idcard.idcardtype')->with('idcardtype',$idcardtype);
	}

	public function postAddidcardtype()
	{
		$addidcardtype = refidcardtypes::create(Input::all());

		$log = New adminlog();
		$log->admin_log_admin_id = Session::get('admin_id');	
		$log->admin_log_activity = "Add data type idcard";	
		$log->admin_log_date = date('Y-m-d H:i:s');	
		$log->save();
		return Redirect::to('/idcard/idcardtype')->with('message','Data jenis ID Card berhasil ditambahkan');
	}

	public function postEditidcardtype($id)
	{
		$editidcardtype = refidcardtypes::find($id);
		$editidcardtype->idcard_type_name = Input::get('idcard_type_name');
		$editidcardtype->save();

		$log = New adminlog();
		$log->admin_log_admin_id = Session::get('admin_id');	
		$log->admin_log_activity = "Edit data type idcard";	
		$log->admin_log_date = date('Y-m-d H:i:s');	
		$log->save();
		return Redirect::to('/idcard/idcardtype')->with('message','Data jenis ID Card berhasil diubah');
	}

	public function postDeleteidcardtype()
	{
		$idcards = DB::table('ref_idcard_type')
				->get();
		foreach($idcards as $idcard){
		if(Input::get($idcard->idcard_type_id)=='1'){
			$idcards = DB::table('ref_idcard_type')
					->where('idcard_type_id','=',$idcard->idcard_type_id)
					->update(array('idcard_type_isdelete' => 1));

		$log = New adminlog();
		$log->admin_log_admin_id = Session::get('admin_id');	
		$log->admin_log_activity = "Edit data type idcard";	
		$log->admin_log_date = date('Y-m-d H:i:s');	
		$log->save();
		}
		}
		return Redirect::to('/idcard/idcardtype')->with('message','Data jenis ID Card berhasil dihapus');
	}


	//ID Card Quality
	public function getIdcardquality()
	{
		Session::forget('filter');
		$idcardquality = DB::table('ref_idcard_quality')
		->where('idcard_quality_isdelete','=',0)
		->paginate(10);
		return View::make('admin.idcard.idcardquality')->with('idcardquality',$idcardquality);
	}

	public function postIdcardquality()
	{
		$filter = Input::get('filter');
		Session::put('filter',Input::get('filter'));
		$idcardquality = DB::table('ref_idcard_quality')
		->where('idcard_quality_isdelete','=',0)
		->where('idcard_quality_name','LIKE','%'.$filter.'%')
		->paginate(10);
		return View::make('admin.idcard.idcardquality')->with('idcardquality',$idcardquality);
	}

	public function postAddidcardquality()
	{
		if(Input::get('idcard_quality_qty')==0){
			$qty = 1;
		}else{
		$qty = Input::get('idcard_quality_qty');
		} 
		$addidcardquality = New refidcardquality();
		$addidcardquality->idcard_quality_name = Input::get('idcard_quality_name');
		$addidcardquality->idcard_quality_price = Input::get('idcard_quality_price');
		$addidcardquality->idcard_quality_qty = $qty;
		$addidcardquality->idcard_quality_unit = Input::get('idcard_quality_unit');
		$addidcardquality->save();

		$log = New adminlog();
		$log->admin_log_admin_id = Session::get('admin_id');	
		$log->admin_log_activity = "Add data kualitas idcard";	
		$log->admin_log_date = date('Y-m-d H:i:s');	
		$log->save();
		return Redirect::to('/idcard/idcardquality')->with('message','Data kualitas ID Card berhasil ditambahkan');
	}

	public function postEditidcardquality($id)
	{
		$editidcardquality = refidcardquality::find($id);
		$editidcardquality->idcard_quality_name = Input::get('idcard_quality_name');
		$editidcardquality->idcard_quality_price = Input::get('idcard_quality_price');
		$editidcardquality->idcard_quality_qty = Input::get('idcard_quality_qty');
		$editidcardquality->idcard_quality_unit = Input::get('idcard_quality_unit');
		$editidcardquality->save();

		$log = New adminlog();
		$log->admin_log_admin_id = Session::get('admin_id');	
		$log->admin_log_activity = "Edit data kualitas idcard ".$id;	
		$log->admin_log_date = date('Y-m-d H:i:s');	
		$log->save();
		return Redirect::to('/idcard/idcardquality')->with('message','Data kualitas ID Card berhasil diubahn');
	}

	public function postDeleteidcardquality()
	{
		$idcards = DB::table('ref_idcard_quality')
				->get();
		foreach($idcards as $idcard){
		if(Input::get($idcard->idcard_quality_id)=='1'){
			$idcards = DB::table('ref_idcard_quality')
					->where('idcard_quality_id','=',$idcard->idcard_quality_id)
					->update(array('idcard_quality_isdelete' => 1));

		$log = New adminlog();
		$log->admin_log_admin_id = Session::get('admin_id');	
		$log->admin_log_activity = "Delete data kualitas idcard ".$idcard->idcard_quality_id;	
		$log->admin_log_date = date('Y-m-d H:i:s');	
		$log->save();
		}
		}
		return Redirect::to('/idcard/idcardquality')->with('message','Data kualitas ID Card berhasil dihapus');
	}


	// //ADD Features
	// public function getIdcardaddfeatures()
	// {
	// 	$idcardaddfeatures = DB::table('ref_additional_features')
	// 						->where('additional_features_isdelete','=',0)
	// 						->paginate(10);
	// 	return View::make('admin.idcard.idcardaddfeatures')->with('idcardaddfeatures',$idcardaddfeatures);
	// }

	// public function postIdcardaddfeatures()
	// {
	// 	$filter = Input::get('filter');
	// 	$idcardaddfeatures = DB::table('ref_additional_features')
	// 	->where('additional_features_isdelete','=',0)
	// 	->where('additional_features_name','LIKE','%'.$filter.'%')
	// 	->paginate(10);
	// 	return View::make('admin.idcard.idcardaddfeatures')->with('idcardaddfeatures',$idcardaddfeatures);
	// }

	// public function postAddidcardaddfeatures()
	// {
	// 	$addidcardaddfeatures = refidcardadditionalfeatures::create(Input::all());
	// 	return Redirect::to('/idcard/idcardaddfeatures')->with('message','Data fitur tambahan ID Card berhasil ditambahkan');
	// }

	// public function postEditidcardaddfeatures($id)
	// {
	// 	$editidcardaddfeatures = refidcardadditionalfeatures::find($id);
	// 	$editidcardaddfeatures->additional_features_name = Input::get('additional_features_name');
	// 	$editidcardaddfeatures->additional_features_price = Input::get('additional_features_price');
	// 	$editidcardaddfeatures->additional_features_unit = Input::get('additional_features_unit');
	// 	$editidcardaddfeatures->save();
	// 	return Redirect::to('/idcard/idcardaddfeatures')->with('message','Data fitur tambahan ID Card berhasil diubahn');
	// }

	// public function postDeleteidcardaddfeatures()
	// {
	// 	$idcards = DB::table('ref_additional_features')
	// 			->get();
	// 	foreach($idcards as $idcard){
	// 	if(Input::get($idcard->additional_features_id)=='1'){
	// 		$id = Input::get($idcard->additional_features_id);
	// 		$idcards = DB::table('ref_additional_features')
	// 				->where('additional_features_id','=',$idcard->additional_features_id)
	// 				->update(array('additional_features_isdelete' => 1));
	// 	}
	// 	}
	// 	return Redirect::to('/idcard/idcardaddfeatures')->with('message','Data fitur tambahan ID Card berhasil dihapus');
	// }
}